package koscom.corebase.nam;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Enumeration;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.text.MaskFormatter;
import javax.swing.text.NumberFormatter;

import redis.clients.jedis.Jedis;

@SuppressWarnings("serial")

public class A2007 extends JFrame {

	private JPanel contentPane;
	private JTextField txtBuyStockNum;
	private JTextField txtBuyStockName;
	private JTextField txtBuyOrderNum;
	private JTextField txtSellStockNum;
	private JTextField txtSellStockName;
	private JTextField txtSellOrderNum;
	private JPanel panBuy;
	private JPanel panSell;
	private JPanel panModify;
	private JPanel panCancel;
	private JFormattedTextField txtAccNum;
	private JPasswordField txtPassword;
	private JTextField txtAccName;
	private JTextField txtStockName;
	private JTextField txtJGKField;
	private JTextField txtModifyStockNum;
	private JTextField txtModifyStockName;
	private JTextField txtModifyOrderNum;
	private JTextField txtModifyOriginOrderNum;
	private JTextField txtCancelStockNum;
	private JTextField txtCancelStockName;
	private JTextField txtCancelOrderNum;
	private JTextField txtCancelOriginOrderNum;
	private static JTable c10Table;
	private static JTable cTable;
	private JTable tblOrderResult;
	private JTable tblOrderFail;
	private JTable tblAccBalance;
	private JTable tblPossiblePrice;
	private JTable tblWarrant;
	private JTextField txtResult;

	JTextField txtCurrentItemCode; // 시세
	JTextField txtCurrentItemName;

	JTextField txtCurrentStockName;
	JSpinner spnBuyAmount;
	JSpinner spnBuyPrice;
	JSpinner spnCancelAmount;
	JSpinner spnModifyAmount;
	JSpinner spnModifyPrice;
	DefaultTableModel mdlOrderResult;
	DefaultTableModel mdlOrderFail;
	DefaultTableModel mdlAccBalance;
	DefaultTableModel warrant_model;

	JButton btnBuy10;
	JButton btnBuy100;
	JButton btnBuy1000;
	JButton btnBuy10000;
	SClient client;
	String currentAccountNumber;
	String currentItemID;
	String currentItemJGK;
	NumberFormatter numberFormatter;

	int canModifyOrCancelAmount;

	public static DecimalFormat dformat = new DecimalFormat("###,###");
	public static MarketPriceCellRenderer leftCellRenderer;
	public static MarketPriceCellRenderer rightCellRenderer;
	public static boolean renderReady = false;

	Jedis jedis = null;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		//기본 폰트 설정
		try {
			
//			for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
//			{
//				if ("Nimbus".equals(info.getName())) {
//					UIManager.setLookAndFeel(info.getClassName());
//					break;
//				}
//			}
			
			UIManager.getDefaults().put("Button.margin", new Insets(0,0,0,0));
			UIDefaults swingComponentDefaultTable = UIManager.getDefaults();
			Enumeration<Object> allDefaultKey = swingComponentDefaultTable.keys();
			while(allDefaultKey.hasMoreElements()) {
				String defaultKey = allDefaultKey.nextElement().toString();
				if(defaultKey.indexOf("font") != -1) {
					Font newDefaultFont = new Font("맑은 고딕", Font.PLAIN, 12);
					//System.out.println(defaultKey);
					UIManager.put(defaultKey, newDefaultFont);
				}   
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					A2007 frame = new A2007();
					frame.setVisible(true);

				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

		RQReader R = new RQReader("nam_sise");
		new Thread(R).run();
	}

	/**
	 * Create the frame.
	 */
	public A2007() {
		jedis = new Jedis("192.168.172.137");
		
		MaskFormatter mf1 = null;
		try {
			mf1 = new MaskFormatter("###-##-######");
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		currentItemID=null;
		currentItemJGK=null;
		currentAccountNumber=null;

		client = new SClient(null, 0, false);
		//onRcvData
		client.setListener(new SClient.OnListener() {
			@Override
			public void onRcvData(ByteBuffer rcvBuff) {
				try {
					byte[] trid = new byte[6];
					rcvBuff.get(trid, 0, trid.length);
					String trString = new String(trid, "UTF-8");

					if(trString.equals("2222OO"))
					{
						System.out.println("2222OO");
						byte[] bytes = new byte[rcvBuff.remaining()];
						rcvBuff.get(bytes);
						String rString = new String(bytes, "UTF-8");
						txtAccName.setText(rString.substring(0,20).trim());
						txtPassword.setText("");
						mdlOrderResult.setRowCount(0);
						mdlOrderFail.setRowCount(0);
						getExecuteList();
						//						mdlAccHistory.setRowCount(0);
						//						mdlAccStat.setRowCount(0);
						//						btnOK.setEnabled(false);
					}
					else if(trString.equals("2222OW")) //계좌&비번 조회 성공
					{
						System.out.println("2222OW");
						currentAccountNumber = txtAccNum.getText();
					}
					else if(trString.equals("2222XX"))
					{
						System.out.println("2222XX");
						txtResult.setText("해당 계좌가 존재하지 않습니다");
						txtAccName.setText("");
						txtPassword.setText("");
						//						mdlAccHistory.setRowCount(0);
						//						mdlAccStat.setRowCount(0);
						//						btnOK.setEnabled(false);
					}
					else if(trString.equals("2222PX"))
					{
						System.out.println("2222PX");
						txtResult.setText("비밀번호가 일치하지 않습니다");
						txtPassword.setText("");
						//						btnOK.setEnabled(false);
						//						mdlAccHistory.setRowCount(0);
						//						mdlAccStat.setRowCount(0);
					}
					else if(trString.equals("2222IO"))
					{
						txtResult.setText("종목조회가 완료되었습니다");
						byte[] itemIDByte = new byte[50];
						rcvBuff.get(itemIDByte, 0, 50);
						String itemName = new String(itemIDByte, "UTF-8").trim();

						itemIDByte = new byte[12];
						rcvBuff.get(itemIDByte, 0, 12);
						currentItemID = new String(itemIDByte, "UTF-8").trim();

						itemIDByte = new byte[20];
						rcvBuff.get(itemIDByte, 0, 20);
						currentItemJGK = new String(itemIDByte, "UTF-8").trim();

						//System.out.println(currentItemID);
						txtCurrentStockName.setText(itemName);

						txtStockName.setText(itemName);
						txtJGKField.setText("거래소"+"\t"+currentItemJGK+"%");

					}
					else if(trString.equals("2222IX"))
					{
						txtResult.setText("종목이 존재하지 않습니다");

						txtBuyStockName.setText("");
						txtStockName.setText("");
						txtJGKField.setText("");
					}
					else if(trString.equals("2007MX"))
					{
						byte[] itemIDByte = new byte[1];
						rcvBuff.get(itemIDByte, 0, 1);
						String mxType = new String(itemIDByte, "UTF-8").trim();
						if(mxType.equals("L"))
						{
							txtResult.setText("매수 주문이 불가능합니다.(주문 금액이 하한가 미만)");
						}
						else if(mxType.equals("U"))
						{
							txtResult.setText("매수 주문이 불가능합니다.(주문 금액이 상한가 초과)");
						}
						else if(mxType.equals("X"))
						{
							txtResult.setText("매수 주문이 불가능합니다.(주문 가능금액 초과)");
						}
						else if(mxType.equals("T"))
						{
							txtResult.setText("매수 주문이 불가능합니다.(거래 금지 종목)");
						}
					}
					else if(trString.equals("2007MD"))
					{
						txtResult.setText("매수 주문이 완료되었습니다");
						byte[] itemIDByte = new byte[10];
						rcvBuff.get(itemIDByte, 0, 10);
						String orderNum = new String(itemIDByte, "UTF-8").trim();
						txtBuyOrderNum.setText(orderNum);
						mdlOrderResult.setRowCount(0);
						mdlOrderFail.setRowCount(0);
						getExecuteList();
						panelAllClear(panBuy);

					}
					else if(trString.equals("2007JD"))
					{
						txtResult.setText("매수 정정 주문이 완료되었습니다");
						byte[] itemIDByte = new byte[10];
						rcvBuff.get(itemIDByte, 0, 10);
						String orderNum = new String(itemIDByte, "UTF-8").trim();
						txtModifyOrderNum.setText(orderNum);
						mdlOrderResult.setRowCount(0);
						mdlOrderFail.setRowCount(0);
						getExecuteList();
						panelAllClear(panModify);
					}
					else if(trString.equals("2007FX"))
					{
						txtResult.setText("미체결 주문이 존재하지 않습니다");
					}
					else if(trString.equals("2007CD"))
					{
						txtResult.setText("매수 취소 주문이 완료되었습니다");
						byte[] itemIDByte = new byte[10];
						rcvBuff.get(itemIDByte, 0, 10);
						String cOrderNum = new String(itemIDByte, "UTF-8").trim();
						txtCancelOrderNum.setText(cOrderNum);
						mdlOrderResult.setRowCount(0);
						mdlOrderFail.setRowCount(0);
						getExecuteList();
						panelAllClear(panCancel);
					}
					else if(trString.equals("2007FD"))
					{
						txtResult.setText("미체결 주문 조회가 완료되었습니다");

						byte[] itemIDByte = new byte[10];
						rcvBuff.get(itemIDByte, 0, 10);
						String orderNum = new String(itemIDByte, "UTF-8").trim();
						txtCancelOriginOrderNum.setText(orderNum);
						txtModifyOriginOrderNum.setText(orderNum);

						itemIDByte = new byte[30];
						rcvBuff.get(itemIDByte, 0, 30);
						String unexAmount = new String(itemIDByte, "UTF-8").trim();
						spnCancelAmount.setValue(Integer.parseInt(unexAmount));
						spnModifyAmount.setValue(Integer.parseInt(unexAmount));

						canModifyOrCancelAmount = Integer.parseInt(unexAmount);

						itemIDByte = new byte[20];
						rcvBuff.get(itemIDByte, 0, 20);
						String itemID = new String(itemIDByte, "UTF-8").trim();
						txtCancelStockNum.setText(itemID);
						txtModifyStockNum.setText(itemID);

						itemIDByte = new byte[50];
						rcvBuff.get(itemIDByte, 0, 50);
						String itemName = new String(itemIDByte, "UTF-8").trim();

						itemIDByte = new byte[10];
						rcvBuff.get(itemIDByte, 0, 10);
						currentItemJGK = new String(itemIDByte, "UTF-8").trim();

						itemIDByte = new byte[20];
						rcvBuff.get(itemIDByte, 0, 20);
						currentItemID = new String(itemIDByte, "UTF-8").trim();

						txtModifyStockName.setText(itemName);
						txtCancelStockName.setText(itemName);
						txtStockName.setText(itemName);
						txtJGKField.setText(currentItemJGK+"%");
					}
					else if(trString.equals("20079A"))
					{
						String line[] = new String[14];
						byte[] exListByte = new byte[10];
						rcvBuff.get(exListByte, 0, 10);
						String oid = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[10];
						rcvBuff.get(exListByte, 0, 10);
						String wid = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[20];
						rcvBuff.get(exListByte, 0, 20);
						String iid = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[50];
						rcvBuff.get(exListByte, 0, 50);
						String iname = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[5];
						rcvBuff.get(exListByte, 0, 5);
						String otype = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[20];
						rcvBuff.get(exListByte, 0, 20);
						String oamount = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[20];
						rcvBuff.get(exListByte, 0, 20);
						String oprice = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[20];
						rcvBuff.get(exListByte, 0, 20);
						String eamount = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[20];
						rcvBuff.get(exListByte, 0, 20);
						String enamount = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[20];
						rcvBuff.get(exListByte, 0, 20);
						String eprice = new String(exListByte, "UTF-8").trim();

						exListByte = new byte[20];
						rcvBuff.get(exListByte, 0, 20);
						String etime = new String(exListByte, "UTF-8").trim();

						line[0] = oid;
						line[1] = wid;
						line[2] = iid;
						line[3] = iname;

						if(otype.equals("0002"))
							line[4] = new String("신규매수");
						else if(otype.equals("0023"))
							line[4] = new String("매수정정");
						else if(otype.equals("0001"))
							line[4] = new String("신규매도");
						else if(otype.equals("0013"))
							line[4] = new String("매도정정");
						line[5] = oamount;
						line[6] = String.format("%,d", Integer.parseInt(oprice));
						line[7] = eamount;
						line[8] = enamount;
						line[9] = String.format("%,d", Integer.parseInt(eprice));
						line[10] = new String("");
						line[11] = new String("지정가");
						line[12] = new String("거래소");
						line[13] = etime;
						if(enamount.equals("0"))
						{
							mdlOrderResult.addRow(line);
						}
						else
						{
							mdlOrderResult.addRow(line);
							mdlOrderFail.addRow(line);
						}
					}
				}catch(Exception rcvex){}
			}
		});

		setTitle("CoreBASE - 주문");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1024, 775);

		ImageIcon a = new ImageIcon("img\\search-icon-hi.png");
		Image img = a.getImage();  
		Image newimg = img.getScaledInstance(22, 22,  java.awt.Image.SCALE_SMOOTH);

		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		panBuy = new JPanel();
		panBuy.addComponentListener(new ComponentAdapter() {
			@Override
			public void componentShown(ComponentEvent e) {
				panelAllClear(panBuy);
				txtCurrentItemCode = txtBuyStockNum;
				txtCurrentItemName = txtBuyStockName;
			}
		});
		panBuy.setBounds(0, 100, 462, 260);
		//contentPane.add(buy);
		panBuy.setLayout(null);

		txtBuyStockNum = new JTextField();
		txtBuyStockNum.setBounds(70, 10, 115, 21);
		txtBuyStockNum.setDocument(new JTextFieldLimit(12));
		txtBuyStockNum.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if(e.getKeyCode()==KeyEvent.VK_ENTER)
				{
					findItemName(txtBuyStockNum, txtBuyStockName);
				}
			}
		});
		txtBuyStockNum.getDocument().addDocumentListener(new DocumentListener(){

			@Override
			public void insertUpdate(DocumentEvent e) { 
				findItem();
			}

			@Override
			public void removeUpdate(DocumentEvent e) { 
				findItem();
			}

			@Override
			public void changedUpdate(DocumentEvent e) {
				findItem();
			}
			
		});
		panBuy.add(txtBuyStockNum);

		JComboBox cmbBuyPriceType = new JComboBox();
		cmbBuyPriceType.setModel(new DefaultComboBoxModel(new String[] {"0. 지정가"}));
		cmbBuyPriceType.setBounds(70, 103, 193, 23);
		panBuy.add(cmbBuyPriceType);

		JLabel lblNewLabel = new JLabel("종목번호");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(15, 13, 50, 15);
		panBuy.add(lblNewLabel);

		JLabel label = new JLabel("매수수량");
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		label.setBounds(15, 44, 50, 15);
		panBuy.add(label);

		JLabel label_1 = new JLabel("매수단가");
		label_1.setHorizontalAlignment(SwingConstants.RIGHT);
		label_1.setBounds(15, 74, 50, 15);
		panBuy.add(label_1);

		JLabel label_2 = new JLabel("호가유형");
		label_2.setHorizontalAlignment(SwingConstants.RIGHT);
		label_2.setBounds(15, 107, 50, 15);
		panBuy.add(label_2);

		txtBuyStockName = new JTextField();
		txtBuyStockName.setText("종목명");
		txtBuyStockName.setEditable(false);
		txtBuyStockName.setBounds(219, 10, 201, 21);
		panBuy.add(txtBuyStockName);
		txtBuyStockName.setColumns(10);

		JButton btnBuyStockSearch = new JButton("");
		btnBuyStockSearch.setBorder(null);
		btnBuyStockSearch.setIcon(new ImageIcon(newimg));

		btnBuyStockSearch.setBounds(186, 10, 22, 22);
		panBuy.add(btnBuyStockSearch);

		spnBuyAmount = new JSpinner();
		spnBuyAmount.setBounds(70, 40, 115, 22);
		panBuy.add(spnBuyAmount);

		spnBuyPrice = new JSpinner();
		spnBuyPrice.setBounds(70, 71, 115, 22);
		panBuy.add(spnBuyPrice);

		btnBuy10 = new JButton("10");
		btnBuy10.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				spnBuyAmount.setValue((Integer)spnBuyAmount.getValue()+10);
			}
		});
		btnBuy10.setFocusPainted(false);
		btnBuy10.setBounds(220, 39, 50, 23);
		panBuy.add(btnBuy10);

		btnBuy100 = new JButton("100");
		btnBuy100.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				spnBuyAmount.setValue((Integer)spnBuyAmount.getValue()+100);
			}
		});
		btnBuy100.setBounds(270, 39, 50, 23);
		btnBuy100.setFocusPainted(false);
		panBuy.add(btnBuy100);

		btnBuy1000 = new JButton("1000");
		btnBuy1000.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				spnBuyAmount.setValue((Integer)spnBuyAmount.getValue()+1000);
			}
		});
		btnBuy1000.setBounds(320, 39, 50, 23);
		btnBuy1000.setFocusPainted(false);
		panBuy.add(btnBuy1000);

		btnBuy10000 = new JButton("10000");
		btnBuy10000.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				spnBuyAmount.setValue((Integer)spnBuyAmount.getValue()+10000);
			}
		});
		btnBuy10000.setBounds(370, 39, 50, 23);
		btnBuy10000.setFocusPainted(false);
		panBuy.add(btnBuy10000);

		JLabel label_3 = new JLabel(">");
		label_3.setForeground(Color.ORANGE);
		label_3.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_3.setBounds(7, 13, 11, 15);
		panBuy.add(label_3);

		JLabel label_4 = new JLabel(">");
		label_4.setForeground(Color.ORANGE);
		label_4.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_4.setBounds(7, 44, 11, 15);
		panBuy.add(label_4);

		JLabel label_5 = new JLabel(">");
		label_5.setForeground(Color.ORANGE);
		label_5.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_5.setBounds(7, 74, 11, 15);
		panBuy.add(label_5);

		JLabel label_6 = new JLabel(">");
		label_6.setForeground(Color.ORANGE);
		label_6.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_6.setBounds(7, 107, 11, 15);
		panBuy.add(label_6);

		JButton btnBuy = new JButton("매수");
		btnBuy.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//매수버튼 클릭!
				ByteBuffer sendBuffer = ByteBuffer.allocateDirect(1024);
				sendBuffer.clear();
				System.out.println("신규 매수 주문!");
				sendBuffer.position(0);
				sendBuffer.limit(6);
				sendBuffer.put("2007MS".getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+11);
				sendBuffer.put(txtAccNum.getText().replaceAll("-", "").getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+12);
				sendBuffer.put(currentItemID.getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+20);
				sendBuffer.put(String.format("%20d", spnBuyAmount.getValue()).getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+20);
				sendBuffer.put(String.format("%20d", spnBuyPrice.getValue()).getBytes());

				sendBuffer.limit(1024);
				sendBuffer.rewind();
				client.writeBuffer(sendBuffer);
				sendBuffer.clear();
			}
		});
		btnBuy.setFont(new Font("맑은 고딕", Font.BOLD, 18));
		btnBuy.setBounds(275, 195, 140, 55);
		btnBuy.setFocusPainted(false);
		panBuy.add(btnBuy);

		JLabel label_7 = new JLabel("주");
		label_7.setHorizontalAlignment(SwingConstants.CENTER);
		label_7.setBounds(185, 44, 22, 15);
		panBuy.add(label_7);

		JLabel label_8 = new JLabel("원");
		label_8.setHorizontalAlignment(SwingConstants.CENTER);
		label_8.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_8.setBounds(185, 75, 22, 15);
		panBuy.add(label_8);

		JLabel label_9 = new JLabel(">");
		label_9.setForeground(Color.ORANGE);
		label_9.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_9.setBounds(7, 230, 10, 15);
		panBuy.add(label_9);

		JLabel label_10 = new JLabel("주문번호");
		label_10.setHorizontalAlignment(SwingConstants.RIGHT);
		label_10.setBounds(15, 230, 50, 15);
		panBuy.add(label_10);

		txtBuyOrderNum = new JTextField();
		txtBuyOrderNum.setEditable(false);
		txtBuyOrderNum.setColumns(10);
		txtBuyOrderNum.setBounds(70, 227, 115, 21);
		panBuy.add(txtBuyOrderNum);
		panBuy.setVisible(true);
		panBuy.setVisible(true);

		panCancel = new JPanel();
		panCancel.addComponentListener(new ComponentAdapter() {
			@Override
			public void componentShown(ComponentEvent e) {
				panelAllClear(panCancel);
				txtCurrentItemCode = txtCancelStockNum;
				txtCurrentItemName = txtCancelStockName;
			}
		});
		panCancel.setBounds(0, 100, 462, 260);
		panCancel.setLayout(null);

		txtCancelStockNum = new JTextField();
		txtCancelStockNum.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if(e.getKeyCode()==KeyEvent.VK_ENTER)
				{
					findItemName(txtCancelStockNum, txtCancelStockName);
				}
			}
		});
		
		txtCancelStockNum.getDocument().addDocumentListener(new DocumentListener(){

			@Override
			public void insertUpdate(DocumentEvent e) {
				findItem();
			}

			@Override
			public void removeUpdate(DocumentEvent e) {
				findItem();
			}

			@Override
			public void changedUpdate(DocumentEvent e) {
				findItem();
			}
			
		});
		
		txtCancelStockNum.setColumns(10);
		txtCancelStockNum.setBounds(80, 42, 115, 21);
		panCancel.add(txtCancelStockNum);

		JLabel label_37 = new JLabel("종목번호");
		label_37.setHorizontalAlignment(SwingConstants.RIGHT);
		label_37.setBounds(15, 45, 50, 15);
		panCancel.add(label_37);

		JLabel label_38 = new JLabel("취소수량");
		label_38.setHorizontalAlignment(SwingConstants.RIGHT);
		label_38.setBounds(15, 76, 50, 15);
		panCancel.add(label_38);

		txtCancelStockName = new JTextField();
		txtCancelStockName.setEditable(false);
		txtCancelStockName.setColumns(10);
		txtCancelStockName.setBounds(234, 42, 184, 21);
		panCancel.add(txtCancelStockName);

		JButton btnCancelStockSearch = new JButton("");
		btnCancelStockSearch.setBorder(null);
		btnCancelStockSearch.setBounds(200, 41, 22, 22);
		btnCancelStockSearch.setIcon(new ImageIcon(newimg));
		panCancel.add(btnCancelStockSearch);

		spnCancelAmount = new JSpinner();
		spnCancelAmount.setBounds(80, 72, 115, 22);
		panCancel.add(spnCancelAmount);

		JLabel label_41 = new JLabel(">");
		label_41.setForeground(Color.ORANGE);
		label_41.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_41.setBounds(7, 45, 11, 15);
		panCancel.add(label_41);

		JLabel label_42 = new JLabel(">");
		label_42.setForeground(Color.ORANGE);
		label_42.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_42.setBounds(7, 76, 11, 15);
		panCancel.add(label_42);

		JButton btnCancel = new JButton("취소");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(canModifyOrCancelAmount < (Integer)spnCancelAmount.getValue())
				{
					txtResult.setText("정정 주문 수량이 정정 가능 수량("+canModifyOrCancelAmount+") 을 초과하였습니다");
				}
				ByteBuffer sendBuffer = ByteBuffer.allocateDirect(1024);
				sendBuffer.clear();
				System.out.println("매수 취소 주문!");
				sendBuffer.position(0);
				sendBuffer.limit(6);
				sendBuffer.put("2007CC".getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+10);
				sendBuffer.put(txtCancelOriginOrderNum.getText().getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+20);
				sendBuffer.put(String.format("%20d", spnCancelAmount.getValue()).getBytes());

				sendBuffer.limit(1024);
				sendBuffer.rewind();
				client.writeBuffer(sendBuffer);
				sendBuffer.clear();
			}
		});
		btnCancel.setFont(new Font("맑은 고딕", Font.BOLD, 18));
		btnCancel.setFocusPainted(false);
		btnCancel.setBounds(275, 195, 140, 55);
		panCancel.add(btnCancel);

		JLabel label_45 = new JLabel("주");
		label_45.setHorizontalAlignment(SwingConstants.CENTER);
		label_45.setBounds(195, 76, 22, 15);
		panCancel.add(label_45);

		JLabel label_47 = new JLabel(">");
		label_47.setForeground(Color.ORANGE);
		label_47.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_47.setBounds(7, 230, 10, 15);
		panCancel.add(label_47);

		JLabel label_48 = new JLabel("주문번호");
		label_48.setHorizontalAlignment(SwingConstants.RIGHT);
		label_48.setBounds(15, 230, 50, 15);
		panCancel.add(label_48);

		txtCancelOrderNum = new JTextField();
		txtCancelOrderNum.setEditable(false);
		txtCancelOrderNum.setColumns(10);
		txtCancelOrderNum.setBounds(70, 227, 115, 21);
		panCancel.add(txtCancelOrderNum);

		JLabel label_49 = new JLabel(">");
		label_49.setForeground(Color.ORANGE);
		label_49.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_49.setBounds(7, 12, 11, 15);
		panCancel.add(label_49);

		JLabel label_50 = new JLabel("원주문번호");
		label_50.setHorizontalAlignment(SwingConstants.RIGHT);
		label_50.setBounds(15, 13, 60, 15);
		panCancel.add(label_50);

		txtCancelOriginOrderNum = new JTextField();
		txtCancelOriginOrderNum.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				//미체결 textfield 엔터입력
				if(e.getKeyCode()==KeyEvent.VK_ENTER)
				{
					findUnexeOrder(txtCancelOriginOrderNum);
				}
			}
		});
		txtCancelOriginOrderNum.setColumns(10);
		txtCancelOriginOrderNum.setBounds(80, 10, 115, 21);
		panCancel.add(txtCancelOriginOrderNum);

		JButton btnCancelRemainedOrder = new JButton("미체결");
		btnCancelRemainedOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtCancelOriginOrderNum.setText("");
				findUnexeOrder(txtCancelOriginOrderNum);
			}
		});
		btnCancelRemainedOrder.setBorder(null);
		btnCancelRemainedOrder.setBounds(200, 9, 70, 23);
		panCancel.add(btnCancelRemainedOrder);

		panModify = new JPanel();
		panModify.addComponentListener(new ComponentAdapter() {
			@Override
			public void componentShown(ComponentEvent e) {
				panelAllClear(panModify);
				txtCurrentItemCode = txtModifyStockNum;
				txtCurrentItemName = txtModifyStockName;
			}
		});
		panModify.setBounds(0, 100, 462, 260);
		panModify.setLayout(null);

		txtModifyStockNum = new JTextField();
		txtModifyStockNum.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if(e.getKeyCode()==KeyEvent.VK_ENTER)
				{
					findItemName(txtModifyStockNum, txtModifyStockName);
				}
			}
		});
		txtModifyStockNum.getDocument().addDocumentListener(new DocumentListener(){

			@Override
			public void insertUpdate(DocumentEvent e) {
				findItem();
			}

			@Override
			public void removeUpdate(DocumentEvent e) {
				findItem();
			}

			@Override
			public void changedUpdate(DocumentEvent e) {
				findItem();
			}
			
		});
		
		txtModifyStockNum.setColumns(10);
		txtModifyStockNum.setBounds(80, 42, 115, 21);
		panModify.add(txtModifyStockNum);

		JComboBox cmbModifyPriceType = new JComboBox();
		cmbModifyPriceType.setModel(new DefaultComboBoxModel(new String[] {"0. 지정가"}));
		cmbModifyPriceType.setBounds(80, 135, 193, 23);
		panModify.add(cmbModifyPriceType);

		JLabel label_23 = new JLabel("종목번호");
		label_23.setHorizontalAlignment(SwingConstants.RIGHT);
		label_23.setBounds(15, 45, 50, 15);
		panModify.add(label_23);

		JLabel label_24 = new JLabel("정정수량");
		label_24.setHorizontalAlignment(SwingConstants.RIGHT);
		label_24.setBounds(15, 76, 50, 15);
		panModify.add(label_24);

		JLabel label_25 = new JLabel("정정단가");
		label_25.setHorizontalAlignment(SwingConstants.RIGHT);
		label_25.setBounds(15, 107, 50, 15);
		panModify.add(label_25);

		JLabel label_26 = new JLabel("호가유형");
		label_26.setHorizontalAlignment(SwingConstants.RIGHT);
		label_26.setBounds(15, 139, 50, 15);
		panModify.add(label_26);

		txtModifyStockName = new JTextField();
		txtModifyStockName.setEditable(false);
		txtModifyStockName.setColumns(10);
		txtModifyStockName.setBounds(234, 42, 184, 21);
		panModify.add(txtModifyStockName);

		JButton btnModifyStockSearch = new JButton("");
		btnModifyStockSearch.setBorder(null);
		btnModifyStockSearch.setBounds(200, 41, 22, 22);
		btnModifyStockSearch.setIcon(new ImageIcon(newimg));
		panModify.add(btnModifyStockSearch);

		spnModifyAmount = new JSpinner();
		spnModifyAmount.setBounds(80, 72, 115, 22);
		panModify.add(spnModifyAmount);

		spnModifyPrice = new JSpinner();
		spnModifyPrice.setBounds(80, 103, 115, 22);
		panModify.add(spnModifyPrice);

		JLabel label_27 = new JLabel(">");
		label_27.setForeground(Color.ORANGE);
		label_27.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_27.setBounds(7, 45, 11, 15);
		panModify.add(label_27);

		JLabel label_28 = new JLabel(">");
		label_28.setForeground(Color.ORANGE);
		label_28.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_28.setBounds(7, 76, 11, 15);
		panModify.add(label_28);

		JLabel label_29 = new JLabel(">");
		label_29.setForeground(Color.ORANGE);
		label_29.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_29.setBounds(7, 107, 11, 15);
		panModify.add(label_29);

		JLabel label_30 = new JLabel(">");
		label_30.setForeground(Color.ORANGE);
		label_30.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_30.setBounds(7, 139, 11, 15);
		panModify.add(label_30);

		JButton btnModify = new JButton("정정");
		btnModify.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(canModifyOrCancelAmount < (Integer)spnModifyAmount.getValue())
				{
					txtResult.setText("정정 주문 수량이 정정 가능 수량("+canModifyOrCancelAmount+") 을 초과하였습니다");
					return;
				}
				ByteBuffer sendBuffer = ByteBuffer.allocateDirect(1024);
				sendBuffer.clear();
				System.out.println("매수 정정 주문!");
				sendBuffer.position(0);
				sendBuffer.limit(6);
				sendBuffer.put("2007JJ".getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+11);
				sendBuffer.put(txtAccNum.getText().replaceAll("-", "").getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+10);
				sendBuffer.put(txtModifyOriginOrderNum.getText().getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+20);
				sendBuffer.put(String.format("%20d", spnModifyAmount.getValue()).getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+20);
				sendBuffer.put(String.format("%20d", spnModifyPrice.getValue()).getBytes());

				sendBuffer.position(sendBuffer.limit());
				sendBuffer.limit(sendBuffer.limit()+12);
				sendBuffer.put(currentItemID.getBytes());

				sendBuffer.limit(1024);
				sendBuffer.rewind();
				client.writeBuffer(sendBuffer);
				sendBuffer.clear();
			}
		});
		btnModify.setFont(new Font("맑은 고딕", Font.BOLD, 18));
		btnModify.setFocusPainted(false);
		btnModify.setBounds(275, 195, 140, 55);
		panModify.add(btnModify);

		JLabel label_31 = new JLabel("주");
		label_31.setHorizontalAlignment(SwingConstants.CENTER);
		label_31.setBounds(195, 76, 22, 15);
		panModify.add(label_31);

		JLabel label_32 = new JLabel("원");
		label_32.setHorizontalAlignment(SwingConstants.CENTER);
		label_32.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_32.setBounds(195, 107, 22, 15);
		panModify.add(label_32);

		JLabel label_33 = new JLabel(">");
		label_33.setForeground(Color.ORANGE);
		label_33.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_33.setBounds(7, 230, 10, 15);
		panModify.add(label_33);

		JLabel label_34 = new JLabel("주문번호");
		label_34.setHorizontalAlignment(SwingConstants.RIGHT);
		label_34.setBounds(15, 230, 50, 15);
		panModify.add(label_34);

		txtModifyOrderNum = new JTextField();
		txtModifyOrderNum.setEditable(false);
		txtModifyOrderNum.setColumns(10);
		txtModifyOrderNum.setBounds(70, 227, 115, 21);
		panModify.add(txtModifyOrderNum);

		JLabel label_35 = new JLabel(">");
		label_35.setForeground(Color.ORANGE);
		label_35.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_35.setBounds(7, 12, 11, 15);
		panModify.add(label_35);

		JLabel label_36 = new JLabel("원주문번호");
		label_36.setHorizontalAlignment(SwingConstants.RIGHT);
		label_36.setBounds(15, 13, 60, 15);
		panModify.add(label_36);

		txtModifyOriginOrderNum = new JTextField();
		txtModifyOriginOrderNum.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				findUnexeOrder(txtModifyOriginOrderNum);
			}
		});
		txtModifyOriginOrderNum.setColumns(10);
		txtModifyOriginOrderNum.setBounds(80, 10, 115, 21);
		panModify.add(txtModifyOriginOrderNum);

		JButton btnModifyRemainedOrder = new JButton("미체결");
		btnModifyRemainedOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				txtModifyOriginOrderNum.setText("");
				spnModifyPrice.setValue(new Integer(0));
				findUnexeOrder(txtModifyOriginOrderNum);
			}
		});
		btnModifyRemainedOrder.setBorder(null);
		btnModifyRemainedOrder.setBounds(200, 9, 70, 23);
		panModify.add(btnModifyRemainedOrder);

		JLabel lnlAccNum = new JLabel("계좌번호");
		lnlAccNum.setBounds(8, 42, 50, 15);
		contentPane.add(lnlAccNum);


		txtAccNum = new JFormattedTextField(mf1);
		txtAccNum.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER){
					findAccountName();
				}
			}
		});
		txtAccNum.setText("계좌번호");
		txtAccNum.setBounds(70, 39, 100, 21);
		contentPane.add(txtAccNum);
		txtAccNum.setColumns(10);

		txtPassword = new JPasswordField();
		txtPassword.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
					getOrderListByPW();
				}
			}
		});
		txtPassword.setBounds(293, 39, 80, 21);
		txtPassword.setDocument(new JTextFieldLimit(4));
		contentPane.add(txtPassword);
		txtPassword.setColumns(10);

		txtAccName = new JTextField();
		txtAccName.setFocusable(false);
		txtAccName.setEditable(false);
		txtAccName.setBounds(182, 39, 100, 21);
		contentPane.add(txtAccName);
		txtAccName.setColumns(10);

		txtStockName = new JTextField();
		txtStockName.setBorder(null);
		txtStockName.setText("종목명");
		txtStockName.setEditable(false);
		txtStockName.setBounds(454, 39, 100, 21);
		contentPane.add(txtStockName);
		txtStockName.setColumns(10);

		txtJGKField = new JTextField();
		txtJGKField.setBorder(null);
		txtJGKField.setText("증거금율");
		txtJGKField.setEditable(false);
		txtJGKField.setBounds(566, 39, 190, 21);
		contentPane.add(txtJGKField);
		txtJGKField.setColumns(10);

		JTabbedPane tpnOrder = new JTabbedPane(JTabbedPane.TOP);
		tpnOrder.setBounds(7, 70, 435, 300);
		contentPane.add(tpnOrder);

		panSell = new JPanel();
		panSell.setBounds(0, 100, 462, 260);
		panSell.setVisible(false);
		panSell.setLayout(null);

		txtSellStockNum = new JTextField();
		txtSellStockNum.setColumns(10);
		txtSellStockNum.setBounds(70, 10, 115, 21);
		panSell.add(txtSellStockNum);

		JComboBox cmbSellPriceType = new JComboBox();
		cmbSellPriceType.setModel(new DefaultComboBoxModel(new String[] {"0. 지정가"}));
		cmbSellPriceType.setBounds(70, 103, 193, 23);
		panSell.add(cmbSellPriceType);

		JLabel label_11 = new JLabel("종목번호");
		label_11.setHorizontalAlignment(SwingConstants.RIGHT);
		label_11.setBounds(15, 13, 50, 15);
		panSell.add(label_11);

		JLabel label_12 = new JLabel("매도수량");
		label_12.setHorizontalAlignment(SwingConstants.RIGHT);
		label_12.setBounds(15, 44, 50, 15);
		panSell.add(label_12);

		JLabel label_13 = new JLabel("매도단가");
		label_13.setHorizontalAlignment(SwingConstants.RIGHT);
		label_13.setBounds(15, 74, 50, 15);
		panSell.add(label_13);

		JLabel label_14 = new JLabel("호가유형");
		label_14.setHorizontalAlignment(SwingConstants.RIGHT);
		label_14.setBounds(15, 107, 50, 15);
		panSell.add(label_14);

		txtSellStockName = new JTextField();
		txtSellStockName.setEditable(false);
		txtSellStockName.setColumns(10);
		txtSellStockName.setBounds(219, 10, 201, 21);
		panSell.add(txtSellStockName);

		JButton btnSellStockSearch = new JButton("");
		btnSellStockSearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ItemSearch is = new ItemSearch(jedis, txtBuyStockNum);
				is.setVisible(true);
			}
		});
		btnSellStockSearch.setBorder(new EmptyBorder(0, 0, 0, 0));
		btnSellStockSearch.setBounds(186, 10, 22, 22);
		btnSellStockSearch.setIcon(new ImageIcon(newimg));
		panSell.add(btnSellStockSearch);

		JSpinner spnSellAmount = new JSpinner();
		spnSellAmount.setBounds(70, 40, 115, 22);
		panSell.add(spnSellAmount);

		JSpinner spnSellPrice = new JSpinner();
		spnSellPrice.setBounds(70, 71, 115, 22);
		panSell.add(spnSellPrice);

		JButton btnSell10 = new JButton("10");
		btnSell10.setFocusPainted(false);
		btnSell10.setBounds(220, 39, 50, 23);
		panSell.add(btnSell10);

		JButton btnSell100 = new JButton("100");
		btnSell100.setFocusPainted(false);
		btnSell100.setBounds(270, 39, 50, 23);
		panSell.add(btnSell100);

		JButton btnSell1000 = new JButton("1000");
		btnSell1000.setFocusPainted(false);
		btnSell1000.setBounds(320, 39, 50, 23);
		panSell.add(btnSell1000);

		JButton btnSell10000 = new JButton("10000");
		btnSell10000.setFocusPainted(false);
		btnSell10000.setBounds(370, 39, 50, 23);
		panSell.add(btnSell10000);

		JLabel label_15 = new JLabel(">");
		label_15.setForeground(Color.ORANGE);
		label_15.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_15.setBounds(7, 13, 11, 15);
		panSell.add(label_15);

		JLabel label_16 = new JLabel(">");
		label_16.setForeground(Color.ORANGE);
		label_16.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_16.setBounds(7, 44, 11, 15);
		panSell.add(label_16);

		JLabel label_17 = new JLabel(">");
		label_17.setForeground(Color.ORANGE);
		label_17.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_17.setBounds(7, 74, 11, 15);
		panSell.add(label_17);

		JLabel label_18 = new JLabel(">");
		label_18.setForeground(Color.ORANGE);
		label_18.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_18.setBounds(7, 107, 11, 15);
		panSell.add(label_18);

		JButton btnSell = new JButton("매도");
		btnSell.setFont(new Font("맑은 고딕", Font.BOLD, 18));
		btnSell.setFocusPainted(false);
		btnSell.setBounds(275, 195, 140, 55);
		panSell.add(btnSell);

		JLabel label_19 = new JLabel("주");
		label_19.setHorizontalAlignment(SwingConstants.CENTER);
		label_19.setBounds(185, 44, 22, 15);
		panSell.add(label_19);

		JLabel label_20 = new JLabel("원");
		label_20.setHorizontalAlignment(SwingConstants.CENTER);
		label_20.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_20.setBounds(185, 75, 22, 15);
		panSell.add(label_20);

		JLabel label_21 = new JLabel(">");
		label_21.setForeground(Color.ORANGE);
		label_21.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		label_21.setBounds(7, 230, 10, 15);
		panSell.add(label_21);

		JLabel label_22 = new JLabel("주문번호");
		label_22.setHorizontalAlignment(SwingConstants.RIGHT);
		label_22.setBounds(15, 230, 50, 15);
		panSell.add(label_22);

		txtSellOrderNum = new JTextField();
		txtSellOrderNum.setEditable(false);
		txtSellOrderNum.setColumns(10);
		txtSellOrderNum.setBounds(70, 227, 115, 21);
		panSell.add(txtSellOrderNum);
		tpnOrder.add(panSell);
		tpnOrder.setTitleAt(0, "매도");
		tpnOrder.add(panBuy);
		tpnOrder.setTitleAt(1, "매수");
		tpnOrder.add(panModify);
		tpnOrder.setTitleAt(2, "정정");
		tpnOrder.add(panCancel);
		tpnOrder.setTitleAt(3, "취소");

		JTabbedPane tpnMarketData = new JTabbedPane(JTabbedPane.TOP);
		tpnMarketData.setBounds(454, 70, 550, 300);
		contentPane.add(tpnMarketData);

		JScrollPane c10ScrollPane = new JScrollPane();
		c10ScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
		tpnMarketData.addTab("현재가(10호가)", null, c10ScrollPane, null);

		cTable = new JTable();
		cTable.setEnabled(false);

		Object[][] data = new Object[][] {
				{"현재가", null, "전일종가", null},
				{"대비", null, "시가", null},
				{"등락률(%)", null, "고가", null},
				{"거래량", null, "저가", null},
				{"거래대금", null, "예상가", null},
				{"상장주식수", null, "예상대비", null},
				{"시가총액", null, "등락률", null},
				{"PER", null, "예상거래량", null},
				{null,  null, "대용가", null},
		};
		String[] columnNames = new String[] {
				"", "", "", ""
		};

		DefaultTableModel model = new DefaultTableModel(data, columnNames);
		cTable = new JTable( model )
		{
			public Component prepareRenderer(
	    			TableCellRenderer renderer, int row, int column)
	    		{
	    			Component c = super.prepareRenderer(renderer, row, column);
	    			JComponent jc = (JComponent)c;
	    			c.setBackground(column%2==1? getBackground() : new Color(195,216,235));//new Color(250,240,190));
	    			Border b;
	    			b = BorderFactory.createCompoundBorder();
	    	        if(
	    	        	((column==0 || column==1) && row==4) || 
	    	        	((column==2 || column==3) && (row==3 || row == 7))
	    	        )
	    	        {
	    	        	jc.setBorder(BorderFactory.createCompoundBorder(b, BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(195,216,235) )));
	    	        }
	    			return c;
	    		}

		};
		cTable.setPreferredScrollableViewportSize(cTable.getPreferredSize());
		cTable.setShowGrid(false);
		cTable.setIntercellSpacing(new Dimension(0,0));

		JScrollPane cScrollPane = new JScrollPane();
		cScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
		cScrollPane.setViewportView(cTable);
		tpnMarketData.addTab("현재가", null, cScrollPane, null);

		for (int row = 0; row < cTable.getRowCount(); row++)
		{
			cTable.setRowHeight(row, (tpnMarketData.getHeight()-30)/cTable.getRowCount());
		}



		Object[][] c10Data = new Object[][] {
				{null,null, null, "전일종가", null},
				{null,null,null,"현재가",null},
				{null,null,null,"대비",null},
				{null,null,null,"등락율",null},
				{null,null,null,"거래량",null},
				{"시  가",null,null,null,null},
				{"고  가",null,null,null,null},
				{"저  가",null,null,null,null},
				{"상한가",null,null,null,null},
				{"하한가",null,null,null,null},
				{null,null,"합계",null,null},
				{null,null,"시간외",null,null}
		};
		String[] c10ColumnNames = new String[] {
			"대비","매도잔량","","매수잔량","대비"
		};

		DefaultTableModel c10Model = new DefaultTableModel(c10Data, c10ColumnNames);

		c10Table = new JTable(c10Model)
		{
			public Component prepareRenderer(
	    			TableCellRenderer renderer, int row, int column)
	    		{
	    			Component c = super.prepareRenderer(renderer, row, column);
	    			JComponent jc = (JComponent)c;
	    			Border b;
	    			b = BorderFactory.createCompoundBorder();
	    			if(row==4||row==9||row==10)
	    			{
	    				jc.setBorder(BorderFactory.createCompoundBorder(b, BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray )));
	    			}
	    			if( (column==0 && (row>4 && row<10)) ||
	    				(column==2 && row>9) ||
	    				(column==3 && row<5)
	    				)
	    			{
	    				c.setBackground(new Color(195,216,235));
	    			}
	    			else
	    			{
	    				c.setBackground(getBackground());
	    			}
	    			
	    			return c;
	    		}

	    	public TableCellRenderer getCellRenderer(int row, int column)
	    	{
	    		if(renderReady && column == 1 && row <5) //왼쪽
	    		{
	    			leftCellRenderer.setStringPainted(true);
	    			leftCellRenderer.setBorder(BorderFactory.createEmptyBorder());
	    			return leftCellRenderer;
	    		}
	    		else if(renderReady && column==3 && row>=5 && row <10) //오른쪽
	    		{
	    			rightCellRenderer.setStringPainted(true);
	    			rightCellRenderer.setBorder(BorderFactory.createEmptyBorder());
	    			return rightCellRenderer;
	    		}
	    		else
	    			return super.getCellRenderer(row, column);
	    	}
		};

		c10Table.setShowGrid(false);
		c10Table.setIntercellSpacing(new Dimension(0,0));
		c10Table.setShowVerticalLines(true);
		for (int row = 0; row < c10Table.getRowCount(); row++)
		{
			c10Table.setRowHeight(row, (tpnMarketData.getHeight()-40)/c10Table.getRowCount());
		}

		c10ScrollPane.setViewportView(c10Table);

		for(int cNum=0; cNum<c10Table.getColumnCount(); cNum++)
		{
			DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
			if(cNum==2)
			{
				dtcr.setHorizontalAlignment(SwingConstants.CENTER);
				c10Table.getColumnModel().getColumn(cNum).setCellRenderer(dtcr);
			}
			else
			{
				dtcr.setHorizontalAlignment(SwingConstants.RIGHT);
				c10Table.getColumnModel().getColumn(cNum).setCellRenderer(dtcr);
			}
		}


		JTabbedPane statTabbedPane = new JTabbedPane(JTabbedPane.TOP);
		statTabbedPane.setBounds(7, 380, 997, 320);
		contentPane.add(statTabbedPane);

		JScrollPane scpOrderResult = new JScrollPane();
		statTabbedPane.addTab("실시간주문체결", null, scpOrderResult, null);

		mdlOrderResult = new DefaultTableModel(
				null,
				new String[] {
						"\uC8FC\uBB38#", "\uC6D0\uC8FC\uBB38#", "\uC885\uBAA9\uCF54\uB4DC", "\uC885\uBAA9\uBA85", "\uC8FC\uBB38\uAD6C\uBD84", "\uC8FC\uBB38\uC218\uB7C9", "\uC8FC\uBB38\uAC00\uACA9", "\uCCB4\uACB0\uC218\uB7C9", "\uBBF8\uCCB4\uACB0\uC218\uB7C9", "\uCCB4\uACB0\uAC00\uACA9", "주문처리","호가구분","시장명","처리시간"
				}
				);

		tblOrderResult = new JTable(mdlOrderResult);
		scpOrderResult.setViewportView(tblOrderResult);

		JScrollPane scpOrderFail = new JScrollPane();
		statTabbedPane.addTab("실시간주문미체결", null, scpOrderFail, null);

		mdlOrderFail = new DefaultTableModel(
				null,
				new String[] {
						"\uC8FC\uBB38#", "\uC6D0\uC8FC\uBB38#", "\uC885\uBAA9\uCF54\uB4DC", "\uC885\uBAA9\uBA85", "\uC8FC\uBB38\uAD6C\uBD84", "\uC8FC\uBB38\uC218\uB7C9", "\uC8FC\uBB38\uAC00\uACA9", "\uCCB4\uACB0\uC218\uB7C9", "\uBBF8\uCCB4\uACB0\uC218\uB7C9", "\uCCB4\uACB0\uAC00\uACA9", "주문처리","호가구분","시장명","처리시간"
				}
				);
		tblOrderFail = new JTable(mdlOrderFail);
		scpOrderFail.setViewportView(tblOrderFail);


		TableColumn tblClm = tblOrderResult.getColumnModel().getColumn(2);
		tblClm.setMinWidth(100);
		tblClm.setMaxWidth(100);
		tblClm.setPreferredWidth(100);
		tblClm.setWidth(100);

		tblClm = tblOrderFail.getColumnModel().getColumn(2);
		tblClm.setMinWidth(100);
		tblClm.setMaxWidth(100);
		tblClm.setPreferredWidth(100);
		tblClm.setWidth(100);

		for(int cNum=0; cNum<tblOrderFail.getColumnCount(); cNum++)
		{
			DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
			if(cNum==6 || cNum==9)
			{
				dtcr.setHorizontalAlignment(SwingConstants.RIGHT);
				tblOrderFail.getColumnModel().getColumn(cNum).setCellRenderer(dtcr);
				tblOrderResult.getColumnModel().getColumn(cNum).setCellRenderer(dtcr);
			}
			else
			{
				dtcr.setHorizontalAlignment(SwingConstants.CENTER);
				tblOrderFail.getColumnModel().getColumn(cNum).setCellRenderer(dtcr);
				tblOrderResult.getColumnModel().getColumn(cNum).setCellRenderer(dtcr);
			}
		}

		JScrollPane scpAccBalance = new JScrollPane();
		statTabbedPane.addTab("실시간잔고조회", null, scpAccBalance, null);

		mdlAccBalance = new DefaultTableModel(
				new Object[][] {
						{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
				},
				new String[] {
						"\uC885\uBAA9\uCF54\uB4DC", "\uC885\uBAA9\uBA85", "\uC794\uACE0\uAD6C\uBD84", "D+2\uC218\uB7C9", "\uB9E4\uB3C4\uAC00\uB2A5", "\uBCF4\uC720\uB2E8\uAC00", "\uD604\uC7AC\uAC00", "\uB300\uBE44", "\uB4F1\uB77D\uC728", "\uC190\uC775\uC728", "\uB9E4\uC785\uAE08\uC561", "\uD3C9\uAC00\uAE08\uC561", "\uD3C9\uAC00\uC190\uC775", "\uAE08\uC77C\uB9E4\uC218", "\uAE08\uC77C\uB9E4\uB3C4", "\uC2DC\uC7A5\uBA85"
				}
				);
		tblAccBalance = new JTable();
		scpAccBalance.setViewportView(tblAccBalance);

		JPanel panPossibleOrder = new JPanel();
		statTabbedPane.addTab("주문가능금액", null, panPossibleOrder, null);
		panPossibleOrder.setLayout(null);

		JScrollPane scpPossiblePrice = new JScrollPane();
		scpPossiblePrice.setBounds(0, 0, 500, 291);
		panPossibleOrder.add(scpPossiblePrice);


		Object[][] possible_price_data = new Object[][] {
				{"장내주문가능금액",null,"주문가능수량",null},
				{"코스닥가능금액",null,null,null},
				{"100%주문가능금액",null,"100%주문가능수량",null},
				{"재사용가능금액",null,null,null},
				{"D+1 예수금",null,"D+2 예수금",null},
				{"주문가능현금",null,"주문가능대용금액",null}
		};
		String[] possible_price_columnNames = new String[] {
				"", "", "", ""
		};
		DefaultTableModel possible_price_model = new DefaultTableModel(possible_price_data,possible_price_columnNames);

		tblPossiblePrice = new JTable(possible_price_model)
		{
			public Component prepareRenderer(
					TableCellRenderer renderer, int row, int column)
			{
				Component c = super.prepareRenderer(renderer, row, column);

				if(column==0 || column==2 ||
						(column==3 && (row==1 || row==3))
						)
				{
					c.setBackground(new Color(195,216,235));
				}
				else
				{
					c.setBackground(getBackground());
				}
				return c;
			}
		};

		tblPossiblePrice.setEnabled(false);
		tblPossiblePrice.setShowGrid(false);
		tblPossiblePrice.setIntercellSpacing(new Dimension(0,0));
		scpPossiblePrice.setViewportView(tblPossiblePrice);

		JScrollPane scpWarrant = new JScrollPane();
		scpWarrant.setBounds(509, 48, 483, 243);
		panPossibleOrder.add(scpWarrant);

		Object[][] warrant_data = new Object[][]
				{
				{"유가/예수금",null},
				{"대용금",null},
				{"미수금",null},
				{"증거금현금",null},
				{"증거금대용",null}
				};
		String[] warrant_colNames = new String[] { "","" };

		warrant_model = new DefaultTableModel(warrant_data, warrant_colNames);

		tblWarrant = new JTable(warrant_model)
		{
			public Component prepareRenderer(
					TableCellRenderer renderer, int row, int column)
			{
				Component c = super.prepareRenderer(renderer, row, column);
				if(column==0)
				{
					c.setBackground(new Color(195,216,235));
				}
				else
				{
					c.setBackground(getBackground());
				}

				return c;
			}
		};
		scpWarrant.setViewportView(tblWarrant);

		JLabel lblWarrantTitle = new JLabel("증거금현황");
		lblWarrantTitle.setHorizontalAlignment(SwingConstants.CENTER);
		tblWarrant.setEnabled(false);
		tblWarrant.setShowGrid(false);
		tblWarrant.setIntercellSpacing(new Dimension(0,0));
		lblWarrantTitle.setBounds(509, 0, 483, 15);
		panPossibleOrder.add(lblWarrantTitle);

		for (int row = 0; row < tblPossiblePrice.getRowCount(); row++)
		{
			tblPossiblePrice.setRowHeight(row, scpPossiblePrice.getHeight()/tblPossiblePrice.getRowCount());
			tblWarrant.setRowHeight(row, scpPossiblePrice.getHeight()/tblPossiblePrice.getRowCount());
		}

		DefaultTableCellRenderer dtcr2 = new DefaultTableCellRenderer();
		dtcr2.setHorizontalAlignment(SwingConstants.RIGHT);
		for(int col=0; col < tblPossiblePrice.getColumnCount(); col++)
		{
			if(col%2==0)
				tblPossiblePrice.getColumnModel().getColumn(col).setCellRenderer(dtcr2);
		}

		for(int col=0; col < tblWarrant.getColumnCount(); col++)
		{
			DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer();
			dtcr.setHorizontalAlignment(SwingConstants.CENTER);
			tblWarrant.getColumnModel().getColumn(col).setCellRenderer(dtcr);
		}
		lblWarrantTitle.setSize(lblWarrantTitle.getWidth(), scpPossiblePrice.getHeight()/tblPossiblePrice.getRowCount());

		txtResult = new JTextField();
		txtResult.setForeground(Color.RED);
		txtResult.setEditable(false);
		txtResult.setBounds(8, 710, 996, 21);
		contentPane.add(txtResult);
		txtResult.setColumns(10);
		
		txtCurrentItemCode = txtBuyStockNum;
		txtCurrentItemName = txtBuyStockName;
		
	}// init

	public void getExecuteList()
	{
		if(txtAccNum.getText().length()==13)
		{
			String accountFindString = "200799";
			accountFindString+=String.format("%11s", txtAccNum.getText().replaceAll("-", ""));
			client.writeString(accountFindString);//+"$");
		}
	}

	public void findAccountName()
	{
		if(txtAccNum.getText().length()==13)
		{
			String accountFindString = "2222ID";
			accountFindString+=String.format("%11s", txtAccNum.getText().replaceAll("-", ""));
			client.writeString(accountFindString);//+"$");
			System.out.println("계좌조회"+accountFindString);
			txtResult.setText("계좌조회");
		}
		else
		{
			txtResult.setText("계좌번호 11자리를 입력해 주세요.");	
		}
	}//findAccountName

	public void getOrderListByPW()
	{
		if(txtPassword.getPassword().length!=4)
		{
			if(txtAccNum.getText().length()!=13)
			{
				txtResult.setText("계좌번호11자리, 비밀번호4자리를 입력하여 주십시오.");
			}
			else
			{
				txtResult.setText("비밀번호 4자리를 바르게 입력하여 주십시오.");
			}
		}
		else
		{
			if(txtAccName.getText().isEmpty()) findAccountName();
			//System.out.println("주문 조회");
			String accountFindString = "2222IW";
			accountFindString+=String.format("%11s%4s", txtAccNum.getText().replaceAll("-", ""), new String(txtPassword.getPassword()));
			client.writeString(accountFindString);//+"$");
			//System.out.println(accountFindString);
			txtResult.setText("");
		}
	}

	public void findUnexeOrder(JTextField txtOriginOrderNum)
	{
		if(txtAccNum.getText().replaceAll(" -", "").length()!=13)
		{
			txtResult.setText("계좌번호를 입력하여 주십시오.");
		}
		else
		{
			System.out.println(txtAccNum.getText().length());
			ByteBuffer sendBuffer = ByteBuffer.allocateDirect(1024);
			sendBuffer.clear();
			System.out.println("미체결 주문 내역 조회");
			sendBuffer.position(0);
			sendBuffer.limit(6);
			sendBuffer.put("2007FF".getBytes());

			sendBuffer.position(sendBuffer.limit());
			sendBuffer.limit(sendBuffer.limit()+11);
			sendBuffer.put(txtAccNum.getText().replaceAll("-", "").getBytes());

			sendBuffer.position(sendBuffer.limit());
			sendBuffer.limit(sendBuffer.limit()+10);
			sendBuffer.put(txtOriginOrderNum.getText().getBytes());

			sendBuffer.limit(1024);
			sendBuffer.rewind();
			client.writeBuffer(sendBuffer);
			sendBuffer.clear();
		}
	}
	public void panelAllClear(JPanel p)
	{
		for(Component c : p.getComponents())
		{
			if(c instanceof JTextField)
			{
				((JTextField) c).setText("");
			}
			if(c instanceof JSpinner)
			{
				((JSpinner) c).setValue(new Integer(0));
			}
		}
	}

	public void batchData(int tableType, String itemName)
	{
		switch(tableType)
		{
		case 1: //c10Table
			String jun = jedis.get(itemName+".종가");
			String sang = jedis.get(itemName+".상한가");
			String ha = jedis.get(itemName+".하한가");

			c10Table.setValueAt(dformat.format(Long.parseLong(jun)), 0, 4); 
			c10Table.setValueAt(dformat.format(Long.parseLong(sang)), 8, 1); 
			c10Table.setValueAt(dformat.format(Long.parseLong(ha)), 9, 1);

			String hv = jedis.get(jedis.get(itemName+".종목번호")+".체결가");
			String jusiksu = jedis.get(itemName+".상장주식수");

			if(hv!=null)
			{
				Long siga = Long.parseLong(hv) * Long.parseLong(jusiksu);
				cTable.setValueAt(dformat.format(siga), 6, 1);
				cTable.setValueAt(dformat.format(Long.parseLong(jun)), 0, 3);
				cTable.setValueAt(dformat.format(Long.parseLong(jusiksu)), 5, 1);
				Double v2 = Double.parseDouble(c10Table.getValueAt(2, 4).toString().replaceAll(",",""));
				Double value = Double.parseDouble(c10Table.getValueAt(0, 4).toString().replaceAll(",",""));
				//대비나누기전일종가*100
				double ud_p = v2.doubleValue()/value.doubleValue()*100;
				DecimalFormat d2format = new DecimalFormat("#.##");
				String ud = "("+d2format.format(ud_p)+"%)";
				c10Table.setValueAt(ud, 3, 4); //등락%
				cTable.setValueAt(ud, 2, 1);
			}
			cTable.setValueAt(jedis.get(itemName+".PER"), 7, 1);
			cTable.setValueAt(dformat.format(Long.parseLong(jedis.get(itemName+".대용가"))), 8, 3);

			break;
		case 2: //cTable
			break;
		}
	}
	public static void parsing(int type, String line)
	{
		switch(type)
		{
		case 1://3011
			line.substring(5,17); // 종목코드
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(19, 28))), 2, 4); // 전일대비 2.4
			cTable.setValueAt(dformat.format(Long.parseLong(line.substring(19, 28))), 1, 1); // 전일대비 1.1

			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(28, 37))), 1, 4); // 체결가 1.4
			cTable.setValueAt(dformat.format(Long.parseLong(line.substring(28, 37))), 0, 1); // 체결가 0.1

			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(49, 58))), 5, 1); // 시가 5.1
			cTable.setValueAt(dformat.format(Long.parseLong(line.substring(49, 58))), 1, 3); // 시가 1.3

			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(58, 67))), 6, 1); // 고가 6.1
			cTable.setValueAt(dformat.format(Long.parseLong(line.substring(58, 67))), 2, 3); // 고가 2.3

			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(67, 76))), 7, 1); // 저가 7.1
			cTable.setValueAt(dformat.format(Long.parseLong(line.substring(67, 76))), 3, 3); // 저가 3.3

			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(76, 88))), 4, 4); // 누적체결수량 4.4
			cTable.setValueAt(dformat.format(Long.parseLong(line.substring(76, 88))), 3, 1); // 누적체결수량 3.1

			//line.substring(108, 113); //체결시각 title
			c10Table.getColumnModel().getColumn(2).setHeaderValue( line.substring(108, 110)+":"+line.substring(110, 112)+":"+line.substring(112, 114) );
			c10Table.getTableHeader().repaint();

			//table.setValueAt(arg2.replaceFirst("^0+(?!$)", ""), row, column);


			break;
		case 2://6011

			line.substring(5,17); // 종목코드
			rightCellRenderer = new MarketPriceCellRenderer(0, Integer.parseInt(line.substring(461,473)), Color.red, false);
			rightCellRenderer.setStringPainted(true);
			rightCellRenderer.setBorderPainted(true);
			leftCellRenderer = new MarketPriceCellRenderer(0, Integer.parseInt(line.substring(449,461)), Color.blue, true);
			leftCellRenderer.setBorderPainted(true);
			leftCellRenderer.setStringPainted(true);
			renderReady = true;

			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(29,38))), 4, 2); // 매도호가1 4.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(47,59))), 4, 1); // 매도잔량1 4.1
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(38,47))), 5, 2); // 매수호가1 5.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(59,71))), 5, 3); // 매수잔량1 5.3
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(71,80))), 3, 2); // 매도호가2 3.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(89,101))), 3, 1); // 매도잔량2 3.1
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(80,89))), 6, 2); // 매수호가2 6.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(101,113))), 6, 3); // 매수잔량2 6.3
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(113,122))), 2, 2); // 매도호가3 2.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(122,131))), 7, 2); // 매수호가3 7.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(131,143))), 2, 1); // 매도잔량3 2.1
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(143,155))), 7, 3); // 매수잔량3 7.3
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(155,164))), 1, 2); // 매도호가4 1.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(173,185))), 1, 1); // 매도잔량4 1.1
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(164,173))), 8, 2); // 매수호가4 8.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(185,197))), 8, 3); // 매수잔량4 8.3
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(197,206))), 0, 2); // 매도호가5 0.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(215,227))), 0, 1); // 매도잔량5 0.1
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(206,215))), 9, 2); // 매수호가5 9.2
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(227,239))), 9, 3); // 매수잔량5 9.3
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(449,461))), 10, 1); // 매도총잔량 10.1
			c10Table.setValueAt(dformat.format(Long.parseLong(line.substring(461,473))), 10, 3); // 매수총잔량 10.3

			break;
		default:
			break;	
		}
	}


	public void findItemName(JTextField txtID, JTextField txtName)
	{
		if(txtID.getText().isEmpty() || (txtID.getText().length()!=6 && txtID.getText().length()!=12))
		{
			txtResult.setText("종목번호(6자리 혹은 12자리)를 입력하여 주십시오.");
		}
		else
		{
			txtCurrentStockName = txtName;
			String accountFindString = "2222II";
			if(txtID.getText().length()==6)
				accountFindString+=String.format("%6s", txtID.getText());
			else if(txtID.getText().length()==12)
				accountFindString+=String.format("%12s", txtID.getText());
			client.writeString(accountFindString);
			txtResult.setText("");
		}
	}

	
	public void findItem()
	{
		txtResult.setText("");
		if(txtCurrentItemCode.getText().isEmpty() || (txtCurrentItemCode.getText().length()!=6 && txtCurrentItemCode.getText().length()!=12))
		{
			if(RQReader.isRun || RQReader.isSet)
			{
				RQReader.isSet = false;
				RQReader.isRun = false;
				renderReady = false;
				if(RQReader.bindKeys.size()!=0) RQReader.unbindAll();
			}
		}
		else
		{
			String itemCode = txtCurrentItemCode.getText();
			String itemName = jedis.get(itemCode);
			if(itemName == null)
			{
				txtCurrentItemName.setText("");
				txtJGKField.setText("");
				txtResult.setText("종목번호 6자리 또는 13자리를 입력하십시오");
			}
			else
			{
				txtCurrentItemName.setText(itemName);
				txtJGKField.setText(jedis.get(itemName+".시장명")+"\t"+(int)(Double.parseDouble(jedis.get(itemName+".증거금율"))*100)+"%");
				txtStockName.setText(itemName);
				txtResult.setText("종목 조회가 완료되었습니다.");
				if(RQReader.isSet)
				{
					RQReader.isRun = false;
					RQReader.unbindAll();
					RQReader.bindKeys.clear();
				}

				String code = jedis.get(itemName+".종목번호");
				RQReader.bindKeys.add(code+".A3011");
				RQReader.bindKeys.add(code+".B6011");

				String cData = jedis.get(code+".A3011");
				String hData = jedis.get(code+".B6011");

				if(cData!=null)
					parsing(1, cData);
				if(hData!=null)
					parsing(2, hData);

				batchData(1,itemName);
				RQReader.isSet = true;
			}
		}
	}
}
